package com.education.admin.api.controller.system;

import com.education.common.base.BaseController;
import com.education.common.utils.MapTreeUtils;
import com.education.common.utils.Result;
import com.education.service.system.SystemMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 菜单管理处理层
 * @author Jason
 * @version 1.0.0
 * @date 2021-11-26 19:12
 */
@RestController
@RequestMapping("/system/menu")
public class SystemMenuController extends BaseController {

    @Autowired
    private SystemMenuService systemMenuService;

    /**
     * 获取菜单列表
     * @return
     */
    @GetMapping("getMenuList")
    public Result getMenuList() {
        Result result = systemMenuService.pagination(new HashMap());
        Map dataMap = result.getData();
        List<Map> dataList = MapTreeUtils.buildTreeData((List<Map>) dataMap.get("dataList"));
        dataMap.put("dataList", dataList);
        return result;
    }

    @PostMapping()
    public Result saveOrUpdateMenu(@RequestBody Map params) {
        return systemMenuService.saveOrUpdate(params);
    }
}
